import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class 繁忙的都市 {
    /**
     *https://www.luogu.com.cn/problem/P2330
     * 最小生成树一定是最小瓶颈树, 要求求其中一条最大边尽可能小
     */
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();

    public static int MAXN = 301;
    public static int MAXM = 8001;
    public static int[][] edges = new int[MAXM][3];
    public static int[] farther = new int[MAXN];
    public static int n,m;
    public static void main(String[] args) throws IOException{
        n = in.nextInt();
        m = in.nextInt();
        //填图
        for (int i = 0; i < m; i++) {
            edges[i][0] = in.nextInt();
            edges[i][1] = in.nextInt();
            edges[i][2] = in.nextInt();
        }
        //排序
        Arrays.sort(edges,0,m,(x,y) -> x[2] - y[2]);
        build(n);
        int edgeCnt = 0;
        int max = 0;
            for(int[] cur: edges){
                if(union(cur[0],cur[1])){
                    edgeCnt++;
                    max = Math.max(max,cur[2]);
                }
                if (edgeCnt == n - 1){
                    break;
                }
            }
            out.print(edgeCnt + " " + max);
            out.close();
        }

    private static void build(int n) {
        for (int i = 1; i <= n; i++) {
            farther[i] = i;
        }
    }

    private static int find(int i) {
        if(farther[i] != i){
            farther[i] = find(farther[i]);
        }
        return farther[i];
    }

    private static boolean union(int x,int y){
        int fx = find(x);
        int fy = find(y);
        if(fx != fy){
            farther[fx] = fy;
            return true;
        }else {
            return false;
        }
    }

    public static class Read{
        StringTokenizer st = new StringTokenizer("");
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

        String next() throws IOException{
            while(!st.hasMoreTokens()){
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        int nextInt()throws IOException{
            return Integer.parseInt(next());
        }
    }
}
